package com.aiju.cash.ui.enter;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.aiju.base.activity.BaseTitleActivity;
import com.aiju.cash.R;
import com.aiju.cash.ui.enter.util.EnterHelper;
import com.aiju.cash.util.ImageDialogUtil;
import com.aiju.utils.T;

import java.io.File;

/**
 * @author: 佐为
 * @date: 2017-05-26 09:47
 * @version: V1.0
 * @Description: 门店首页上传
 */
public class HomeImageActivity extends BaseTitleActivity {

    private ImageView imageView;
    private File logoFile;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        setCenterTitle("门店首页");
        setRightTitle("确认上传");
        mAiJuTitleBarView.setRightOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (logoFile != null) {
                    EnterHelper.uploadImageFile(HomeImageActivity.this, mDialogHelper, logoFile);
                } else {
                    T.ToastShort("请选择图片，或替换原有图片");
                }
            }
        });
        imageView = (ImageView) findViewById(R.id.iv_enter_add);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ImageDialogUtil.showSelectPicDialog(HomeImageActivity.this);
            }
        });
        EnterHelper.displayImage(getIntent(), mDialogHelper, imageView);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        logoFile = EnterHelper.onActivityResult(imageView, requestCode, resultCode, data);
    }
}
